{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import joblib\n",
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "INPUT_DIR = './concats_more/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cut_rabbish(train_no, csv_no_list=[]):\n",
    "    '''\n",
    "    描述：\n",
    "        砍掉plc或sensor状态不稳定的时间片段\n",
    "    '''\n",
    "    if not os.path.exists('./concats_cut'):\n",
    "        os.mkdir('./concats_cut')\n",
    "    df = joblib.load(INPUT_DIR + 'concat_0%d.lz4'%train_no)\n",
    "    if csv_no_list == []:\n",
    "        joblib.dump(df, './concats_cut/concat_0%d.lz4'%train_no, compress='lz4')\n",
    "        return\n",
    "    cond = [i not in csv_no_list for i in df['csv_no']]\n",
    "    df_1 = df.loc[cond].copy()\n",
    "    df_1.reset_index(drop=True, inplace=True)\n",
    "    df_1.drop(columns=['csv_no'], inplace=True)\n",
    "   \n",
    "    joblib.dump(df_1, './concats_cut/concat_0%d.lz4'%train_no, compress='lz4')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "cut_rabbish(1, [1,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "cut_rabbish(2, [3,6,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "cut_rabbish(3, [])\n",
    "cut_rabbish(4, [])\n",
    "cut_rabbish(5, [])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
